package com.hongtao3.hsync.vo;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import com.hongtao3.hsync.Hsync;

public class RemoteFile extends File {
	public static Hsync hsync;
	private static final long serialVersionUID = 1L;
	private  HashMap<String,Meta>  metas;
	private Meta meta;

	public RemoteFile(String path){
		super(path);
		try {
			metas=hsync.getMeta(path, false);
			meta=metas.get(path);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public RemoteFile(Meta meta){
		super(meta.getPath());
		this.meta=meta;
	}
	
	@Override
	public boolean delete() {
		return true;
	}

	@Override
	public boolean exists() {
		return metas.containsKey(getPath());
	}

	@Override
	public String getParent() {
		return super.getParent();
	}

	@Override
	public File getParentFile() {
		return new RemoteFile(getParent());
	}

	@Override
	public boolean isDirectory() {
		return meta.getType().equals("d");
	}

	@Override
	public boolean isFile() {
		return meta.getType().equals("f");
	}

	@Override
	public boolean isHidden() {
		return false;
	}

	@Override
	public long lastModified() {
		return meta.getMt();
	}

	@Override
	public long length() {
		return meta.getSize();
	}

	@Override
	public File[] listFiles() {
		File[] fs=new File[metas.size()-1];
		int i=0;
		//metas的第一行总是目录自己
		for(Map.Entry<String, Meta> en:metas.entrySet()){
			if(!en.getValue().getPath().equals(meta.getPath())){
		     fs[i++]=new RemoteFile(en.getValue());	
			}
		 }
		return fs;
	}

	@Override
	public boolean mkdir() {
		return true;
	}


}
